package com.mihoyo.basic.service.impl;

import com.mihoyo.basic.mapper.IBaseMapper;
import com.mihoyo.basic.query.BaseQuery;
import com.mihoyo.basic.service.IBaseService;
import com.mihoyo.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private IBaseMapper<T> mapper;

    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return mapper.findById(id);
    }


    @Override
    public void update(T t) {
        mapper.update(t);

    }

    @Override
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    public void delete(Long id) {
        mapper.delete(id);

    }

    @Override
    public PageList queryByPage(BaseQuery baseQuery) {
        Integer totals = mapper.queryByCount(baseQuery);
        if (totals <= 0) {
            return new PageList();
        }
        List<T> rows = mapper.queryByPage(baseQuery);
        return new PageList(totals, rows) ;
    }

    @Override
    public void batchDelete(List ids) {
        mapper.batchDelete(ids);
    }
}
